package com.ruoyi.system.controller;

import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.system.domain.TbPremisesInfo;
import com.ruoyi.system.service.ITbPremisesInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 楼盘信息Controller
 * 
 * @author ruoyi
 * @date 2021-06-19
 */
@RestController
@RequestMapping("/info")
public class TbPremisesInfoController extends BaseController
{
    @Autowired
    private ITbPremisesInfoService tbPremisesInfoService;


    @PreAuthorize(hasPermi = "resource:info:sellou")
    @PostMapping("/sellou")
    public Map<String, Object> sellou(@RequestBody String name){
        Map<String, Object> map = new HashMap<>();
        TbPremisesInfo selbyname = tbPremisesInfoService.selbyname(name);
        System.out.println(selbyname);
        if(selbyname!=null){
            map.put("ss",200);
            map.put("msg",String.valueOf(selbyname.getId()));
            return map;
        }
        map.put("ss",401);
        return map;
    }


    /**
     * 查询楼盘信息列表
     */
    @PreAuthorize(hasPermi = "system:info:list")
    @GetMapping("/list")
    public TableDataInfo list(TbPremisesInfo tbPremisesInfo)
    {
        startPage();
        List<TbPremisesInfo> list = tbPremisesInfoService.selectTbPremisesInfoList(tbPremisesInfo);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 导出楼盘信息列表
     */
    @PreAuthorize(hasPermi = "system:info:export")
    @Log(title = "楼盘信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbPremisesInfo tbPremisesInfo) throws IOException
    {
        List<TbPremisesInfo> list = tbPremisesInfoService.selectTbPremisesInfoList(tbPremisesInfo);
        ExcelUtil<TbPremisesInfo> util = new ExcelUtil<TbPremisesInfo>(TbPremisesInfo.class);
        util.exportExcel(response, list, "楼盘信息数据");
    }

    /**
     * 获取楼盘信息详细信息
     */
    @PreAuthorize(hasPermi = "system:info:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbPremisesInfoService.selectTbPremisesInfoById(id));
    }

    /**
     * 新增楼盘信息
     */
    @PreAuthorize(hasPermi = "system:info:add")
    @Log(title = "楼盘信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbPremisesInfo tbPremisesInfo)
    {
        return toAjax(tbPremisesInfoService.insertTbPremisesInfo(tbPremisesInfo));
    }

    /**
     * 修改楼盘信息
     */
    @PreAuthorize(hasPermi = "system:info:edit")
    @Log(title = "楼盘信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbPremisesInfo tbPremisesInfo)
    {
        return toAjax(tbPremisesInfoService.updateTbPremisesInfo(tbPremisesInfo));
    }

    /**
     * 删除楼盘信息
     */
    @PreAuthorize(hasPermi = "system:info:remove")
    @Log(title = "楼盘信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbPremisesInfoService.deleteTbPremisesInfoByIds(ids));
    }
}
